/**
 * @date   2011-4-2
 * @author tianye
 */

package cn.edu.dlut.WingGameDemos;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.graphics.Rect;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import cn.edu.dlut.WingGame.BaseType.WingColor;
import cn.edu.dlut.WingGame.Graphic.GLDevice;
import cn.edu.dlut.WingGame.Graphic.GLFont;
import cn.edu.dlut.WingGame.Tools.FPSCounter;

public class Test5 extends Activity {
	private GLSurfaceView mGLView;
	private MyRender5 mRender;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		// 游戏全屏幕
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		GLDevice.setActivity(this);
		GLDevice.setBKColor(200, 200, 200);
		mGLView = new GLSurfaceView(this);
		mRender = new MyRender5();
		mGLView.setRenderer(mRender);
		setContentView(mGLView);
	}

	@Override
	protected void onPause() {
		super.onPause();
		mGLView.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mGLView.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}

class MyRender5 implements GLSurfaceView.Renderer {
	private FPSCounter fps = new FPSCounter();
	private GLFont font1 = new GLFont();
	private GLFont font2 = new GLFont();

	@Override
	public void onDrawFrame(GL10 gl) {
		GLDevice.onDrawFrame(gl);

		font1.drawText(30, 60, "Hello World");
		font1.drawText(30, 120, "WingGame游戏引擎");
		font2
				.drawText(
						new Rect(30, 180, 290, 450),
						"Do not rely on one's appearance;"
								+ "it can deceive.Do not rely on wealth; even that fades away .Rely on"
								+ " someone who makes you smile ; becauce it takes only a smile to make "
								+ "a dark day seem bright.");

		fps.nextFrame();
		fps.drawFPS();
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		GLDevice.onSurfaceChanged(gl, width, height);

	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		GLDevice.onSurfaceCreated(gl, config);
		font1.creatFont("cafe.ttf", 24, new WingColor(255, 0, 0, 255));
		font2.creatFont("bazaronite.ttf", 18, new WingColor(0, 0, 255, 255));
	}

}
